package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.NocvNews;
import com.example.entity.XueYuan;
import com.example.service.NocvNewsService;
import com.example.service.XueYuanService;
import com.example.vo.DataView;
import com.example.vo.NocvNewsVo;
import com.example.vo.XueYuanVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/xueyuan")
public class XueYuanController {

    @Autowired
    private XueYuanService xueYuanService;

    @RequestMapping("/listXueYuan")
    public DataView listXueYuan(XueYuanVo xueYuanVo){
        IPage<XueYuan> page=new Page<>(xueYuanVo.getPage(), xueYuanVo.getLimit());
        QueryWrapper<XueYuan> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(xueYuanVo.getName()),"name",xueYuanVo.getName());
        xueYuanService.page(page,queryWrapper);
        DataView dataView=new DataView(page.getTotal(),page.getRecords());
        return dataView;
    }


    @RequestMapping("/deleteById")
    public DataView deleteById(Integer id){
        xueYuanService.removeById(id);
        DataView dataview=new DataView();
        dataview.setCode(200);
        dataview.setMsg("删除数据成功");
        return dataview;
    }

    @RequestMapping("/addOrUpdateXueYuan")
    public DataView addOrUpdateXueYuan(XueYuan xueYuan){
        boolean save = xueYuanService.saveOrUpdate(xueYuan);
        DataView dataview=new DataView();
        if(save){
            dataview.setCode(200);
            dataview.setMsg("新增数据成功");
            return dataview;
        }
        dataview.setCode(100);
        dataview.setMsg("操作失败");
        return dataview;
    }
}
